package models;

import java.util.List;

import javax.persistence.Entity;

import play.db.jpa.Model;

@Entity
public class NodeConfig extends Model {
    private String name;
    private String nodeIP;

    public NodeConfig(String name, String nodeIP) {
    	this.name = name;
        this.nodeIP = nodeIP;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNodeIP() {
        return nodeIP;
    }

    public void setNodeIP(String nodeIP) {
        this.nodeIP = nodeIP;
    }

    public static List<String> getNodes() {
        return find("SELECT c.nodeIP FROM NodeConfig c GROUP BY c.nodeIP").fetch();
    }   

    public static NodeConfig getProperty(Long id) {
        return find("SELECT c FROM NodeConfig c WHERE c.id=?1", id).first();
    }
    
    public static NodeConfig getPropertyIP(String nodeIP) {
        return find("SELECT c FROM NodeConfig c WHERE c.nodeIP=?1", nodeIP).first();
    }
    
    public static NodeConfig getPropertyName(String name) {
        return find("SELECT c FROM NodeConfig c WHERE c.name=?1", name).first();
    }
    
    @Override
    public String toString() {
        return "NodeConfig [nodeIP=" + nodeIP + "]";
    }
}